﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Imports SecurityService

Partial Class Control_MSDS_Section01
	Inherits System.Web.UI.UserControl
	Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "EVENT FOR CONTROL"

	Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Translate()
        If Not IsPostBack Then
            Me.EnableViewState = False
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "duyjs", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "duyjs", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
            If Not Request.QueryString("Id").ToString.Equals("0") Then
                hidMSDSID.Value = Request.QueryString("Id")
            End If

            CheckData()
        End If
	End Sub
    Protected Sub Translate()
        lblSection01Title.Text=getTranslate("lblSection01Title", Session("LanguageId"), lblSection01Title.Text)
        lbSection01CasNo.Text = getTranslate("lbSection01CasNo", Session("LanguageId"), lbSection01CasNo.Text)
        lbSection01Chemical.Text = getTranslate("lbSection01Chemical", Session("LanguageId"), lbSection01Chemical.Text)
        lbSection01ECNo.Text = getTranslate("lbSection01ECNo", Session("LanguageId"), lbSection01ECNo.Text)
        lbSection01Emergency.Text = getTranslate("lbSection01Emergency", Session("LanguageId"), lbSection01Emergency.Text)
        lbSection01lChemicaleName.Text = getTranslate("lbSection01lChemicaleName", Session("LanguageId"), lbSection01lChemicaleName.Text)
        lbSection01lSynonyms.Text = getTranslate("lbSection01lSynonyms", Session("LanguageId"), lbSection01lSynonyms.Text)
        lbSection01lTradeName.Text = getTranslate("lbSection01lTradeName", Session("LanguageId"), lbSection01lTradeName.Text)
        lbSection01MAddress.Text = getTranslate("lbSection01MAddress", Session("LanguageId"), lbSection01MAddress.Text)
        lbSection01Manufacturer.Text = getTranslate("lbSection01Manufacturer", Session("LanguageId"), lbSection01Manufacturer.Text)
        lbSection01MEmail.Text = getTranslate("lbSection01MEmail", Session("LanguageId"), lbSection01MEmail.Text)
        lbSection01MFax.Text = getTranslate("lbSection01MFax", Session("LanguageId"), lbSection01MFax.Text)
        lbSection01Mname.Text = getTranslate("lbSection01Mname", Session("LanguageId"), lbSection01Mname.Text)
        lbSection01MPhone.Text = getTranslate("lbSection01MPhone", Session("LanguageId"), lbSection01MPhone.Text)
        lbSection01MWebsite.Text = getTranslate("lbSection01MWebsite", Session("LanguageId"), lbSection01MWebsite.Text)
        lbSection01ProducCode.Text = getTranslate("lbSection01ProducCode", Session("LanguageId"), lbSection01ProducCode.Text)
        lbSection01Required.Text = getTranslate("lbSection01Required", Session("LanguageId"), lbSection01Required.Text)
        lbSection01SAddress.Text = getTranslate("lbSection01SAddress", Session("LanguageId"), lbSection01SAddress.Text)
        lbSection01SEmail.Text = getTranslate("lbSection01SEmail", Session("LanguageId"), lbSection01SEmail.Text)
        lbSection01SFax.Text = getTranslate("lbSection01SFax", Session("LanguageId"), lbSection01SFax.Text)
        lbSection01Sname.Text = getTranslate("lbSection01Sname", Session("LanguageId"), lbSection01Sname.Text)
        lbSection01SPhone.Text = getTranslate("lbSection01SPhone", Session("LanguageId"), lbSection01SPhone.Text)
        lbSection01Supplier.Text = getTranslate("lbSection01Supplier", Session("LanguageId"), lbSection01Supplier.Text)
        lbSection01SWebsite.Text = getTranslate("lbSection01SWebsite", Session("LanguageId"), lbSection01SWebsite.Text)
        lbSection01UNNo.Text = getTranslate("lbSection01UNNo", Session("LanguageId"), lbSection01UNNo.Text)
        lbSection01User.Text = getTranslate("lbSection01User", Session("LanguageId"), lbSection01User.Text)

        rfvSection011.ErrorMessage = getTranslate("rfvSection011", Session("LanguageId"), rfvSection011.ErrorMessage)
        'rfvSection012.ErrorMessage = getTranslate("rfvSection012", Session("LanguageId"), rfvSection012.ErrorMessage)
        rfvSection013.ErrorMessage = getTranslate("rfvSection013", Session("LanguageId"), rfvSection013.ErrorMessage)
        rfvSection014.ErrorMessage = getTranslate("rfvSection014", Session("LanguageId"), rfvSection014.ErrorMessage)
        'rfvSection015.ErrorMessage = getTranslate("rfvSection015", Session("LanguageId"), rfvSection015.ErrorMessage)
    End Sub
	Protected Sub btnSection01Save_Click(sender As Object, e As EventArgs) Handles btnSection01Save.Click
		Using data As New VSEntities
			Try
				Dim p As MSDSSection01
				p = (From q In data.MSDSSection01
				Where q.Section01Id = hidID.Value
					 ).FirstOrDefault()
				Dim _isNew = True
				If Not p Is Nothing Then
					_isNew = False
				Else
					p = New MSDSSection01
				End If
				With p
					.S101 = txtS101.Text.Trim
					.S102 = txtS102.Text.Trim
					.S103 = txtS103.Text.Trim
					.S104 = txtS104.Text.Trim
					.S105 = txtS105.Text.Trim
					.S106 = txtS106.Text.Trim
					.S107 = txtS107.Text.Trim
					.S108 = txtS108.Text.Trim
					.S201 = txtS201.Text.Trim
					.S202 = txtS202.Text.Trim
					.S203 = txtS203.Text.Trim
					.S204 = txtS204.Text.Trim
					.S205 = txtS205.Text.Trim
					.S206 = txtS206.Text.Trim
					.S301 = txtS301.Text.Trim
					.S302 = txtS302.Text.Trim
					.S303 = txtS303.Text.Trim
					.S304 = txtS304.Text.Trim
					.S305 = txtS305.Text.Trim
					.S306 = txtS306.Text.Trim
					.S307 = txtS307.Text.Trim
					.LanguageId = Session("LanguageId")
					.MSDSId = hidMSDSID.Value
				End With
				If _isNew Then
					p.Created = Now
					p.Creator = Session("UserName")
					data.MSDSSection01.AddObject(p)
				Else
					p.Modified = Now
					p.Modifier = Session("UserName")
				End If
				data.SaveChanges()

				Insert_App_Log(If(_isNew, "Insert", "Update") & "  MSDS Section01:" & hidMSDSID.Value & "", Function_Name.MSDSOriginal, If(_isNew, Audit_Type.Create, Audit_Type.Edit), Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
				Excute_Javascript("AlertboxRedirect('Lưu dữ liệu thành công.','../../Page/MSDS/Section02.aspx?Id=" & hidMSDSID.Value & "');", Me.Page, True)

			Catch ex As Exception
				log4net.Config.XmlConfigurator.Configure()
				log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
				Excute_Javascript("Alertbox('Cập nhật thất bại.');", Me.Page, True)
			Finally
				GC.Collect()
			End Try
		End Using
	End Sub
	Protected Sub btnSEctionBack_Click(sender As Object, e As EventArgs) Handles btnSEctionBack.Click

	End Sub
#End Region
#Region "PRIAVTE SUB AND FUNCTION"
	Sub CheckData()
		Using data As New VSEntities
			Dim LanguageId = Session("LanguageId").ToString()
			Dim p = (From q In data.MSDSSection01
					 Where q.LanguageId = LanguageId And q.MSDSId = hidMSDSID.Value
					 ).FirstOrDefault()
			If Not p Is Nothing Then
				txtS101.Text = p.S101
				txtS102.Text = p.S102
				txtS103.Text = p.S103
				txtS104.Text = p.S104
				txtS105.Text = p.S105
				txtS106.Text = p.S106
				txtS107.Text = p.S107
				txtS108.Text = p.S108
				txtS201.Text = p.S201
				txtS202.Text = p.S202
				txtS203.Text = p.S203
				txtS204.Text = p.S204
				txtS205.Text = p.S205
				txtS206.Text = p.S206
				txtS301.Text = p.S301
				txtS302.Text = p.S302
				txtS303.Text = p.S303
				txtS304.Text = p.S304
				txtS305.Text = p.S305
				txtS306.Text = p.S306
				txtS307.Text = p.S307
				hidID.Value = p.Section01Id
            End If

		End Using
	End Sub
#End Region

End Class
